package com.visionblue.business.ship.page.dialog

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.visionblue.business.ship.R
import com.visionblue.business.ship.model.bean.response.TransportShipInfo
import kotlinx.android.extensions.LayoutContainer
import kotlinx.android.synthetic.main.item_transporter.*

/**
 * @author: xlh
 * @date: 2020-06-08 5:50 PM
 * @desc:
 */
class SelectionTransportAdapter(private val transporters: List<TransportShipInfo>) :
    RecyclerView.Adapter<SelectionTransportAdapter.VH>() {

    var onItemClickListener: OnItemClickListener? = null

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH {
        val itemView =
            LayoutInflater.from(parent.context).inflate(R.layout.item_transporter, parent, false)
        return VH(itemView)
    }

    override fun getItemCount(): Int {
        return transporters.size
    }

    override fun onBindViewHolder(holder: VH, position: Int) {
        holder.tvShipName.text = transporters[position].shipName
        holder.itemView.setOnClickListener {
            onItemClickListener?.onItemClick(transporters[position].shipNo)
        }
    }

    class VH(override val containerView: View) : RecyclerView.ViewHolder(containerView),
        LayoutContainer {

    }

    interface OnItemClickListener {
        fun onItemClick(shipNo: String?)
    }

}